#include "RGBEdit.h"
#include "StaticText.h"
#include "EditBox.h"

RGBEdit::RGBEdit()
: m_pLabel(NULL)
, m_r(NULL)
, m_g(NULL)
, m_b(NULL)
, m_rBox(NULL)
, m_gBox(NULL)
, m_bBox(NULL)
{
}
RGBEdit::~RGBEdit()
{
	if(m_pLabel)
	{
		delete m_pLabel;
		m_pLabel = NULL;
	}
	if(m_r)
	{
		delete m_r;
		m_r = NULL;
	}
	if(m_g)
	{
		delete m_g;
		m_g = NULL;
	}
	if(m_b)
	{
		delete m_b;
		m_b = NULL;
	}
	if(m_rBox)
	{
		delete m_rBox;
		m_rBox = NULL;
	}
	if(m_gBox)
	{
		delete m_gBox;
		m_gBox = NULL;
	}
	if(m_bBox)
	{
		delete m_bBox;
		m_bBox = NULL;
	}
}
bool RGBEdit::Setup(HWND a_hWnd, HINSTANCE a_hInst, int a_xPos, int a_yPos, int a_labelWidth, int a_labelHeight, char* a_pLabel)
{
	m_pLabel = new StaticText();
	m_pLabel->Setup(a_hWnd, a_hInst, a_xPos, a_yPos, a_labelWidth, a_labelHeight, a_pLabel);

	//Add an offset from the static text box
	a_labelWidth += 5;

	m_r = new StaticText();
	m_r->Setup(a_hWnd, a_hInst, a_xPos + a_labelWidth, a_yPos, 15, 16, "R:");

	m_g = new StaticText();
	m_g->Setup(a_hWnd, a_hInst, a_xPos + 50 + a_labelWidth, a_yPos, 15, 16, "G:");

	m_b = new StaticText();
	m_b->Setup(a_hWnd, a_hInst, a_xPos + 100 + a_labelWidth, a_yPos, 15, 16, "B:");

	m_rBox = new EditBox();
	m_rBox->Setup(a_hWnd, a_hInst, a_xPos + 15 + a_labelWidth, a_yPos, 30, 16);

	m_gBox = new EditBox();
	m_gBox->Setup(a_hWnd, a_hInst, a_xPos + 65 + a_labelWidth, a_yPos, 30, 16);

	m_bBox = new EditBox();
	m_bBox->Setup(a_hWnd, a_hInst, a_xPos + 115 + a_labelWidth, a_yPos, 30, 16);
	
	return true;
}
D3DXCOLOR RGBEdit::GetColour()
{
	return D3DCOLOR_XRGB(m_rBox->GetInt(), m_gBox->GetInt(), m_bBox->GetInt());
}